home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / device.arc / DEVICE.C next >
Encoding:
C/C++ Source or Header  |  1985-06-25  |  7.4 KB  |  195 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  *    Device.C -->>  This Program Will Display Device Driver Chains         *
  4.  *                   for Dos 2.xx and 3.00                                  *
  5.  *                                                                          *
  6.  *    Non-DeSmet Compilers will have to change the following:               *
  7.  *    _os()   --> bdos call --  use bdos()                                  *
  8.  *    _peek() --> peek memory -- must assemble seperatly using macro        *
  9.  *                               form.                                      *
  10.  *    05-20-85                                                              *
  11.  *    Converted to DeSmet "C" by Lord Rassilon                              *
  12.  *                                                                          *
  13.  *    05-01-85                                                              *
  14.  *    Dr. Dobb's #103  May 85   pages 119-126                               *
  15.  ****************************************************************************/
  16.  
  17. #define   byte        char
  18.  
  19. /* DOS Function Calls */
  20. #define   OPEN_FCB    0x0F
  21. #define   CLOSED_FCB  0x10
  22. #define   VERSION     0x30
  23.  
  24.  
  25. /* Define Data Structures */
  26. struct    DEVHDR   {
  27.             unsigned    nxthdr_off;   /* Double word ptr to next */
  28.             unsigned    nxthdr_seg;   /* device header in chain */
  29.             unsigned    attr;         /* Type of device driver */
  30.             unsigned    strat;        /* Device strategy entry point */
  31.             unsigned    intrpt;       /* Interrupt entry point */
  32.             char        dname[8];     /* Device name */
  33.           };
  34.  
  35. struct    FCB      {
  36.             byte        drive;        /* Drive designator */
  37.             char        fname[11];    /* File or device name */
  38.             unsigned    curblk;       /* Current block Set to 0 by OPEN_FCB */
  39.             unsigned    recsize;      /* Logical record size  */ 
  40.                                       /* (Set to 0x80 by OPEN_FCB) */ 
  41.             long        fsize;        /* File size in bytes */
  42.             unsigned    date;         /* Creation or last update date */
  43.             byte        sys_rsv[10];  /* Fields reserved for DOS */
  44.             byte        bset[5];      /* Relative record numbers */
  45.           };
  46.  
  47. struct    RSV2_X   {
  48.             unsigned    time;         /* Creation or last update time */
  49.             byte        attribute;    /* Device or file attribute */
  50.             unsigned    dhdr2_off;    /* Offset address of device header */
  51.             unsigned    dhdr2_seg;    /* Segment address of device header */
  52.             byte        unknown2[3];  /* Unknown usage */
  53.           };
  54.  
  55. struct    RSV3_X   {
  56.             unsigned    time;         /* Creation or last update time */
  57.             byte        attribute;    /* Device or file attribute */
  58.             unsigned    dhdr3_off;    /* Offset address of device header */
  59.             unsigned    dhdr3_seg;    /* Segment address of device header */
  60.             byte        unknown3[2];  /* Unknown usage */
  61.           };
  62.  
  63. struct    DEVHDR      device;       /* Device header */
  64. struct    FCB         device_fcb;   /* Standard FCB for device */
  65. struct    RSV2_X      *dos2x;       /* Reserved field definitions DOS 2.x */
  66. struct    RSV3_X      *dos3x;       /* Reserved field definitions DOS 3.x */
  67.  
  68. main()
  69. {
  70.  int       dev_off,dev_seg,i,j;
  71.  
  72.  initfcb(0,"NUL         ");         /* Set up standard FCB for NUL device */
  73.  
  74.  if (_os(OPEN_FCB,&device_fcb) & 0xFF)  { /* Open the device */
  75.     printf("Unable to open device \n");
  76.     exit(1);
  77.  }
  78.  
  79.     /* the reserved fields are allocated differently for DOS 3.x */
  80.  if  ((_os(VERSION,0) & 0xFF) ==3)   {
  81.     dos3x=(struct RSV3_X *) &device_fcb.sys_rsv[0];
  82.     dev_off=dos3x->dhdr3_off;
  83.     dev_seg=dos3x->dhdr3_seg;
  84.  }
  85.  
  86.  else if ((_os(VERSION,0) & 0xFF) ==2)  {
  87.     dos2x=(struct RSV2_X *) &device_fcb.sys_rsv[0];
  88.     dev_off=dos2x->dhdr2_off;
  89.     dev_seg=dos2x->dhdr2_seg;
  90.  } 
  91.  
  92.  else   {   /* Forget it for DOS 1.10 or earlier */   
  93.     printf("DOS 2.00 or newer required\n");
  94.     exit(1);
  95.  }
  96.  
  97.  printf("   Device driver chain .... \n\n");
  98.  
  99.  /* Display the current DOS chain of device drivers */
  100.  printf("   ptr      type    device name     strategy ptr  interrupt ptr \n");
  101.  printf("----------  ----  ----------------  ------------  ------------- \n");
  102.  
  103.  while((dev_seg != 0xFFFF) & (dev_off != 0xFFFF))  {
  104.       /* device header ptr */
  105.     printf("%04x:%04x  ",dev_seg,dev_off);
  106.  
  107.       /* move the device header into the data segment structure "device" */
  108.     _peek(dev_seg,dev_off,&device,sizeof(device));
  109.  
  110.       /* display device attribute word */
  111.     printf(" %04x  ",device.attr);
  112.  
  113.  
  114.                           
  115.     if ((device.attr & 0x8000) ==0)  {     /* If block device ....   */
  116.         for (j=0;j<=7;j++)                 /* no device name  */
  117.           printf("%02x",device.dname[j]); 
  118.                                            /* strategy end point */         
  119.         printf("   %04x:%04x      ",dev_seg,device.strat); 
  120.     }
  121.  
  122.     else  {   /* display device name */
  123.       for (j=0;j<=7;j++)
  124.         printf("%c",device.dname[j]);
  125.                                           /* strategy end point */
  126.       printf("           %04x:%04x      ",dev_seg,device.strat);
  127.     }
  128.  
  129.       /*  "interupt" entry point */  
  130.     printf("%04x:%04x    \n",dev_seg,device.intrpt); 
  131.    
  132.     dev_seg=device.nxthdr_seg; /* set up ptr to next device header */
  133.     dev_off=device.nxthdr_off; /* and loop back to display it */
  134.  }
  135. printf("----------  ----  ----------------  ------------  ------------- \n");
  136. }
  137.  
  138.  
  139. /* Initialize standard FCB */
  140.  int  initfcb(drv,name)
  141.               byte      drv;
  142.               char      name[];
  143. {
  144.  int  i;
  145.  device_fcb.drive=drv;       /* drive designation: default drive=0, A=1 ... */
  146.  for(i=0;i<=10;i++) device_fcb.fname[i]=name[i]; /* device or file name */
  147.  for(i=0;i<=4;i++) device_fcb.bset[i]=0; /* fields not zeroed by open call */
  148. }
  149.  
  150. /* Peek memory   */
  151.  int  _peek(segment,offset,buffer,nbytes)
  152.             unsigned   segment;   /* segment portion of memory address */
  153.             unsigned   offset;    /* offset portion of memory address */
  154.             byte       *buffer;   /* local memory buffer (in data segment) */
  155.             unsigned   nbytes;    /* number of bytes to transfer */
  156.  
  157. /*
  158.  macro assembler header:
  159.  
  160. PGROUP   GROUP   PROG
  161. PROG     SEGMENT BYTE  PUBLIC 'PROG'
  162.          PUBLIC  _PEEK
  163.          ASSUME  CS:PGROUP
  164. ;
  165. _PEEK    PROC   NEAR
  166.          PUSH   BP
  167.          MOV    BP,SP      */
  168. {
  169. #asm
  170.          PUSH   DS               ;save state
  171.          PUSH   SI
  172.          PUSH   DI
  173.          PUSH   CX
  174.  ;
  175.          MOV    DS,WORD [BP+4]   ;get source segment
  176.          MOV    SI,WORD [BP+6]   ;get source offset
  177.          MOV    DI,WORD [BP+8]   ;get destination offset in ES
  178.          MOV    CX,WORD [BP+10]  ;get byte count for transfer
  179.          REP    MOVSB            ;move bytes into local buffer
  180.  ;
  181.          POP    CX               ;return state
  182.          POP    DI
  183.          POP    SI
  184.          POP    DS
  185. #
  186. }
  187. /*       POP    BP
  188.          RET
  189. _PEEK    ENDP
  190. PROG     ENDS
  191.          END         */
  192.  
  193.  
  194.